package gnv;

import java.io.FileWriter;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
 
public class GenerarListaMail
{
   public static void main(String [] args)
   {
	   generateCsvFile("c:/test.csv"); 
   }
 
   private static void generateCsvFile(String sFileName) 
	{
		try
		{
			
			String sql = "select APENOM, CORREOE from persona " +
					"where (ESTADO = 1 and CORREOE <>''); ";
			java.sql.Connection con = Gnv_Inicio.conectaBase();
			PreparedStatement ps = con.prepareStatement(sql);
			ps.execute();

			ResultSet rs = ps.getResultSet();
			
			
		    FileWriter writer = new FileWriter(sFileName);
 
		    //First,"Middle","Last","Nickname","Email",
		    
		    
			writer.append("First");
			writer.append(',');
			writer.append("Email");
			writer.append('\n');
 
			while (rs.next()){
			writer.append(rs.getString(1));
			writer.append(',');
			writer.append(rs.getString(2));
			writer.append('\n');
			}
 
			//generate whatever data you want
 
			writer.flush();
			writer.close();
		}
		catch(IOException e)
		{
		 e.printStackTrace();
		} catch (Exception error){
			error.printStackTrace();
		}
	}
}